package model.parser;

import java.util.Deque;
import java.util.Queue;

import util.reflection.Reflection;

import model.semantics.Node;
import model.tokens.NodeFactory;

public class BuiltinFunctionDefinition<T> extends FunctionDefinition<T> {
    protected String className;
    protected String[] callArgs;

    @SuppressWarnings("unchecked")
    @Override
    public Node<T> makeNewInstance(Deque<Node<T>> queue, boolean isPrefix) {
        Node<T>[] values = getArgsFromQueue(queue, order, isPrefix);

        /*
         * Create a new instance of the functional token by passing its order,
         * call arguments, and kids.
         */
        Node<T> node = (Node<T>) Reflection.callMethod(
                NodeFactory.getInstance(), className, order, callArgs, values,
                label);
        return node;
    }
}
